package com.xinbochuang.machine.admin.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xinbochuang.machine.admin.domain.AlarmCount;
import com.xinbochuang.machine.admin.domain.CameraAlarmRecord;
import com.xinbochuang.machine.admin.service.ICameraAlarmRecordService;
import com.xinbochuang.machine.common.controller.BaseController;
import com.xinbochuang.machine.common.domain.TableDataInfo;
import com.xinbochuang.machine.framework.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杜文博
 * @date 2020-10-29
 */
@RestController
@RequestMapping("/camera-alarm-record")
public class CameraAlarmRecordController extends BaseController {

    @Autowired
    private ICameraAlarmRecordService iCameraAlarmRecordService;

    /**
     * 分页查询预警列表
     *
     * @param cameraAlarmRecord
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo getCameraAlarmList(CameraAlarmRecord cameraAlarmRecord) {
        return getDataTable(iCameraAlarmRecordService.selectList(cameraAlarmRecord));
    }

    /**
     * 根据Id查询详情
     *
     * @param uuId
     * @return
     */
    @GetMapping("/detail")
    public AjaxResult getCertificationList(@RequestParam("uuid") String uuId) {
        return AjaxResult.data(iCameraAlarmRecordService.getById(uuId));
    }

    /**
     * 处理机房预警记录
     *
     * @param cameraAlarmRecord
     * @return
     */
    @PutMapping("/check")
    public AjaxResult updateCamera(@RequestBody CameraAlarmRecord cameraAlarmRecord) {
        return toAjax(iCameraAlarmRecordService.updateCamera(cameraAlarmRecord));
    }

    /**
     * 告警统计
     */
    @GetMapping("/alarmCount")
    public AjaxResult alarmCount() {
        AjaxResult ar = AjaxResult.ok();
        int total = iCameraAlarmRecordService.count(Wrappers.<CameraAlarmRecord>lambdaQuery().eq(CameraAlarmRecord::getDeleteFlag, 0));
        List<AlarmCount> list = iCameraAlarmRecordService.alarmCount();
        ar.put("total", total);
        ar.put("list", list);
        return ar;
    }

}

